package com.novax.ex.activity.provider.controller.inner;

import com.novax.ex.activity.infrastructure.entity.TaskEtRewardsConfig;
import com.novax.ex.activity.infrastructure.entity.TaskLanguage;
import com.novax.ex.activity.infrastructure.entity.TaskRule;
import com.novax.ex.activity.open.api.inner.TaskEtRewardsConfigApi;
import com.novax.ex.activity.open.api.inner.TaskRuleApi;
import com.novax.ex.activity.open.model.request.task.TaskEtRewardsConfigRequest;
import com.novax.ex.activity.open.model.request.task.TaskRuleRequest;
import com.novax.ex.activity.open.model.response.task.TaskEtRewardsConfigResponse;
import com.novax.ex.activity.open.model.response.task.TaskRuleResponse;
import com.novax.ex.activity.provider.controller.BaseActivityController;
import com.novax.ex.activity.provider.service.TaskEtRewardsConfigService;
import com.novax.ex.activity.provider.service.TaskRuleService;
import com.novax.ex.common.base.BaseEntity;
import com.novax.ex.common.constant.InternationalCode;
import com.novax.ex.common.results.ReturnResult;
import com.novax.ex.common.util.CopyUtils;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RestController;

import jakarta.annotation.Resource;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description 后管 ET解锁难度设定表
 * @Author ChenXi
 * @Date 2023/06/21/10:34
 */

@RestController
public class TaskEtRewardsConfigController extends BaseActivityController implements TaskEtRewardsConfigApi {

    @Resource
    private TaskEtRewardsConfigService taskEtRewardsConfigService;

    @Override
    public ReturnResult<TaskEtRewardsConfigResponse> query() {
        return ReturnResult.success(
            CopyUtils.copyObject(taskEtRewardsConfigService.find(null), TaskEtRewardsConfigResponse.class));
    }

    @Override
    public ReturnResult<?> modify(String language, Long id, TaskEtRewardsConfigRequest taskEtRewardsConfigRequest,
                                  BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            return ReturnResult.fail(getInternational(language, InternationalCode.LACK_VALUE));
        }
        BigDecimal fee = taskEtRewardsConfigRequest.getFee();
        if (fee == null || fee.compareTo(BigDecimal.ZERO) < 0 || fee.compareTo(new BigDecimal("100")) > 0 ||
            fee.stripTrailingZeros()
                .scale() > 0) {
            return ReturnResult.fail(getInternational(language, InternationalCode.POSITIVE_INTEGER));
        }
        TaskEtRewardsConfig taskEtRewardsConfig = CopyUtils.copyObject(taskEtRewardsConfigRequest, TaskEtRewardsConfig.class);
        taskEtRewardsConfig.setId(id);
        boolean flag = taskEtRewardsConfigService.modifySelective(taskEtRewardsConfig);
        return flag ? ReturnResult.success(getInternational(language, InternationalCode.OPERATION_SUCCESS))
            : ReturnResult.fail(getInternational(language, InternationalCode.OPERATION_ERROR));
    }

}
